package com.saas.tenant.controller;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.saas.tenant.entity.User;
import com.saas.tenant.service.UserService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * @auther Jiang Tian
 * @date 2025/2/28
 * @apiNote
 **/
@RestController
@RequestMapping("/user")
public class UserController {

    @Autowired
    private UserService primaryUserService;

    @Autowired
    private UserService secondaryUserService;

    // 查询所有用户
    @GetMapping
    public List<User> getAllUsers() {
        return primaryUserService.list();
    }

    // 根据 ID 查询用户
    @GetMapping("/{id}")
    public User getUserById(@PathVariable Long id) {
        return primaryUserService.getById(id);
    }

    // 根据 ID 查询用户
    @GetMapping("/getUsers")
    public List<User> getUsers() {
        return primaryUserService.list();
    }

    // 添加用户
    @PostMapping("/addUser")
    public boolean addUser(@RequestBody User user) {
        return primaryUserService.save(user);
    }

    @PostMapping("/test")
    public Object test(@RequestBody User user){
        QueryWrapper<User> queryWrapper = new QueryWrapper<>();
        queryWrapper.setEntity(user);
        return primaryUserService.getOne(queryWrapper);
    }

    @PostMapping("/test1")
    public Object test1(){
        return primaryUserService.selectUserInfo();
    }

    @PostMapping("/test2")
    public Object test2(){
        return secondaryUserService.selectUserInfo();
    }
}
